<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/common/common.jsp" %>
<html>
<head>
    <meta charset="utf-8"/>
    <title>厅干部平时考核管理系统</title>
</head>
<body>
<div class="njga" style="overflow: auto;">
    <div class="bmkhcp">
        <div class="bmkhcp_lf" style="width: 100%;">
                <div class="title">考核任务列表</div>
                <div class="khzpzp_row khzpzp_row1">
                    <div class="p_text">年份</div>
                    <div class="zp_select_wraper">
                        <div class="zp_select">
                            <input type="text" class="inpt1 showinpt"/>
                            <input type="text" class="inpt1 hideinpt" style="display: none" id="yearinfo"/>
                            <div class="arrow_down"></div>
                        </div>
                        <ul class="zp_select_xl">
                            <li value="-1">未选择</li>
                            <li value="2017">2017</li>
                            <li value="2018">2018</li>
                            <li value="2019">2019</li>
                            <li value="2020">2020</li>
                            <li value="2021">2021</li>
                            <li value="2022">2022</li>
                        </ul>
                    </div>
                    <div class="p_text" style="width: 90px;text-align:center">考核方式</div>
                    <div class="zp_select_wraper">
                        <div class="zp_select">
                            <input type="text" class="inpt1 showinpt"/>
                            <input type="text" class="inpt1 hideinpt" style="display: none" id="checktype"/>
                            <div class="arrow_down"></div>
                        </div>
                        <ul class="zp_select_xl">
                            <li value="-1">未选择</li>
                            <li value="0">月度考核</li>
                            <li value="1">季度考核</li>
                        </ul>
                    </div>
                    <div class="p_text" style="width: 90px;text-align:center">考核状态</div>
                    <div class="zp_select_wraper">
                        <div class="zp_select">
                            <input type="text" class="inpt1 showinpt"/>
                            <input type="text" class="inpt1 hideinpt" style="display: none" id="checkstatus"/>
                            <div class="arrow_down"></div>
                        </div>
                        <ul class="zp_select_xl">
                            <li value="-1">未选择</li>
                            <li value="0">待设置</li>
                            <li value="1">待考核</li>
                            <li value="2">考核中</li>
                            <li value="3">已完成</li>
                            <li value="4">已停用</li>
                        </ul>
                    </div>
                    <div>
                        <button class="btn btn1" id="search_btn">查询</button>
                    </div>
                    <%--<div class="xzzb_add" id="xzzb_add">反馈设置</div>--%>
                </div>
                <table id="boot_table"></table>
            </div>
    </div>
</div>

<script type="text/javascript">
    var layerindex;
    $(document).ready(function () {
        //查询
        $("#search_btn").on("click", refresBootTable);
        //新建考核任务
        $("#xzzb_add").on("click", function () {
            layerindex = layer.open({
                type: 2, //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）。
                shift: 1, //动画    0-6     css3动画
                closeBtn: 1, //关闭按钮  0 不显示  style  1和2  标题为 false 2
                btn: ['确定', '取消'],
                title: ['新建考核任务', 'background:#5f9ad1;color:#fff;text-align: left;font-size: 18px;'],
                area: ['760px', '420px'], //宽高
                content: "<c:url value='/task/add.html'/>", //iframe层-禁滚动条  $("#photosDemo").html()   'http://www.baidu.com/'
                yes: function (index, layero) {
                    var newtask = $(layero).find("iframe")[0].contentWindow;
                    newtask.submitForm();
                }
            });
        });
        //新建考核任务结束
        //考核情况下拉
        $(document).click(function () {
            $(".zp_select_xl").slideUp(200);
        });
        $(".zp_select_wraper .zp_select").click(function (e) {
            e = e || window.event;
            if (e.stopPropagation) {
                e.stopPropagation();
            } else {
                e.cancelBubble = true;
            }
            $(this).next(".zp_select_xl").slideToggle(200);
            var showselecttext = $(this).children(".showinpt");
            var hideselecttext = $(this).children(".hideinpt");
            var selectmain = $(this).next(".zp_select_xl");
            var lis = selectmain.find('li');
            for (var i = 0; i < lis.length; i++) {
                lis[i].onclick = function () {
                    selectmain.hide();
                    var textval = $(this).val();
                    var texthtml = $(this).html();
                    hideselecttext.val(decodeURIComponent(textval));
                    showselecttext.val(decodeURIComponent(texthtml));
                }
            }
        });
        //考核情况下拉结束

        initTable();//初始化表格
    });


</script>

<script>
    var $table = $('#boot_table'),
            $remove = $('#remove'),
            selections = [];

    function initTable() {
        $table.bootstrapTable({
            idField: "DBID",
            pagination: "true",
            sidePagination: 'server',
            url: "<c:url value='/task/taskData.json'/>",
            height: 556,
            columns: [
                /*{
                 field: 'DBID',
                 checkbox: true,
                 align: 'center',
                 valign: 'middle'
                 }, */{
                    title: '序号',
                    field: 'Number',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var page = $table.bootstrapTable("getOptions");
                        return ((page.pageNumber - 1 ) * page.pageSize) + index + 1;
                    }
                }, {
                    title: '考核名称',
                    field: 'NAME',
                    align: 'center',
                    valign: 'middle'
                }, {
                    field: 'TYPE',
                    title: '考核方式',
                    align: 'center',
                    formatter: function (value, row, index) {
                        switch (value) {
                            case '0':
                                return "月度考核";
                            case '1':
                                return "季度考核";
                            case '2':
                                return "半年考核";
                            default:
                                return "全年考核";
                        }
                    }
                }, {
                    field: 'STARTDATE',
                    title: '开始时间',
                    align: 'center',
                    formatter: ShortDateFormat
                }, {
                    field: 'ENDDATE',
                    title: '结束时间',
                    align: 'center',
                    formatter: ShortDateFormat
                }, {
                    field: 'STATUS',
                    title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        switch (value) {
                            case '0':
                                return "待设置";
                            case '1':
                                return "待考核";
                            case '2':
                                return "考核中";
                            case '3':
                                return "已完成";
                            default:
                                return "已停用";
                        }
                    }
                }, {
                    field: 'DBID',
                    title: '操作',
                    align: 'center',
                    event: {
                        'click .like': function (e, value, row, index) {
                            alert('You click like action, row: ' + JSON.stringify(row));
                        },
                        'click .remove': function (e, value, row, index) {
                            $table.bootstrapTable('remove', {
                                field: 'id',
                                values: [row.id]
                            });
                        }
                    },
                    formatter: operateFormatter
                }

            ]
        });
    }

    function operateFormatter(value, row, index) {
        if (row.STATUS == '0'||row.STATUS == '4') {
            return [].join('');
        } else if (row.STATUS == '1') {
            return [
                '<a href="javascript:gotoRelationRow(\'' + value + '\')" >考核关系设置',
                '</a>'
            ].join('');
        } else {
            return [
                '<a href="javascript:showRelationRow(\'' + value + '\')" >考核关系查看',
                '</a>'
            ].join('');
        }
    }

    function getHeight() {
        return $(window).height() - $('h1').outerHeight(true);
    }


    //停用方法
    function stopRow(id, type) {
        var text = '';
        if (type == '0') {
            text = '禁用';
        } else {
            text = '启用';
        }
        layer.confirm('确认' + text + '?', {icon: 3, title: '提示'}, function (index) {
            layer.close(index);
            $.ajax({
                url: "<c:url value='/task/stopTask/'/>" + id + ".json?type="+ type,
                success: function (data) {
                    if ("1" == data.message.status) {
                        refresBootTable();
                        showMessage("操作成功！");
                    } else {
                        showMessage('无法' + text + '！');
                    }

                }
            })
        });
    }

    //删除方法
    function removeRow(id) {
        layer.confirm('确认删除?', {icon: 3, title: '提示'}, function (index) {
            layer.close(index);
            $.ajax({
                url: "<c:url value='/task/deleteTask/'/>" + id + ".json",
                success: function (data) {
                    refresBootTable();
                    showMessage("操作成功！");
                }
            })
        });
    }

    //编辑方法
    function editRow(dbid) {
        var editlayerindex = layer.open({
            type: 2, //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）。
            shift: 1, //动画    0-6     css3动画
            closeBtn: 1, //关闭按钮  0 不显示  style  1和2  标题为 false 2
            btn: ['确定', '取消'],
            title: ['编辑考核任务', 'background:#5f9ad1;color:#fff;text-align: left;font-size: 18px;'],
            area: ['760px', '420px'], //宽高
            content: "<c:url value='/task/edit/'/>" + dbid + ".html", //iframe层-禁滚动条  $("#photosDemo").html()   'http://www.baidu.com/'
            yes: function (index, layero) {
                var newtask = $(layero).find("iframe")[0].contentWindow;
                newtask.submitForm();
            }
        });
    }

    //考核关系设置方法
    function gotoRelationRow(id) {
        var url = "<c:url value='/task/relation/khrygxsz.html?taskId='/>" + id;
        $('#ifrm_data', parent.document).attr("src", url);
    }
    //考核关系查看方法
    function showRelationRow(id) {
        var url = "<c:url value='/task/relation/khrygxsz.html?taskId='/>" + id;
        $('#ifrm_data', parent.document).attr("src", url);
    }

    //刷新表单方法
    function refresBootTable() {
        $('#boot_table').bootstrapTable('refresh', {url: "<c:url value='/task/taskData.json?check_year='/>" + $("#yearinfo").val() + "&check_type=" + $("#checktype").val() + "&check_status=" + $("#checkstatus").val()});
    }

</script>
</body>

</html>